package com.quectel.emp.config;

import com.quectel.util.servlet.filter.HttpTraceIdFilter;
import com.quectel.util.servlet.filter.XssFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 过滤器配置
 *
 * @author caolu
 * @email louis.cao@quectel.com
 * @date 2023-11-28 14:51:00
 */
@Configuration
public class FilterConfig {
    /**
     * 生成日志追踪id
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean<HttpTraceIdFilter> httpTraceIdFilter() {
        FilterRegistrationBean<HttpTraceIdFilter> filter = new FilterRegistrationBean<>();
        filter.addUrlPatterns("/*");
        filter.setFilter(new HttpTraceIdFilter());
        return filter;
    }

    /**
     * 防止xss攻击
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean<XssFilter> xssFilter() {
        FilterRegistrationBean<XssFilter> filter = new FilterRegistrationBean<>();
        filter.addUrlPatterns("/*");
        filter.setFilter(new XssFilter());
        return filter;
    }
}
